package com.lc.app.androidfirst.userdefine.activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.lc.app.androidfirst.R;
import com.lc.app.androidfirst.userdefine.view.DrawPicture;

public class DrawPictureActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_draw_picture);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = new MenuInflater(this);
        inflater.inflate(R.menu.menu_draw_picture,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        DrawPicture drawPictureView = (DrawPicture) findViewById(R.id.viewDrawPicture);
        drawPictureView.paint.setXfermode(null);

        switch(item.getItemId()){
            case R.id.colorRed:
                drawPictureView.paint.setColor(Color.RED);
                item.setChecked(true);
                break;
            case R.id.colorGreen:
                drawPictureView.paint.setColor(Color.GREEN);
                item.setChecked(true);
                break;
            case R.id.colorBlue:
                drawPictureView.paint.setColor(Color.BLUE);
                item.setChecked(true);
                break;
            case R.id.width1:
                drawPictureView.paint.setStrokeWidth(1);
                item.setChecked(true);
                break;
            case R.id.width5:
                drawPictureView.paint.setStrokeWidth(5);
                item.setChecked(true);
                break;
            case R.id.width10:
                drawPictureView.paint.setStrokeWidth(10);
                item.setChecked(true);
                break;
            case R.id.clear:
                drawPictureView.clear();
                break;
            case R.id.save:
                drawPictureView.save();
                break;
        }
        return true;
    }
}
